/**
 * 当前打开的商品窗口,这个有待考虑
 */
'use strict'
import {query} from "../services/homeService";
import mockjs from "mockjs";

const gmkc = [
  {value: '20', label: '20次'},
  {value: '30', label: '30次'},
  {value: '40', label: '40次'},
  {value: '50', label: '50次'},
];
const mksc = [
  {value: '2', label: '2小时'},
  {value: '1', label: '1小时'},
  {value: '3', label: '3小时'},
];

const data = mockjs.mock({
  'classes|5': [    //课表
    {
      'name': "第@increment(1)节课",
      'time': "09月11日 周二07:00-09:00",
    }
  ],
});

export default {

  namespace: 'product',

  state: {
    currentPruduct: {},
    isBook: false,    //开出下单
    step: 0,          //第几步
    yyxq: {},         //预约详情
    classes: data.classes,      //课表
    yyxqSelect: {
      gmkc: gmkc,
      mksc: mksc,
    },//预约详情选项
    sksj: [],
  },

  subscriptions: {},

  effects: {
    * search({val}, {call, put}) {  // eslint-disable-line
      const res = yield call(_ => query(val));
      console.log(res);
      yield put({type: 'save'});
    },
  },

  reducers: {
    setProduct(state = {}, {data}) {
      console.log('显示详情', data);
      return {...state};
    },
    currentPruduct(state = {}, {currentPruduct = []}) {
      return {...state, currentPruduct};
    },
    isBook(state = {}, {payload = {}}) {
      return {...state, isBook: payload};
    },
    book(state = {}, {payload = {}}) {//开出下单
      return {...state, isBook: true, step: 0};
    },
    next(state = {}, {payload = {}}) {   //下一步
      return {...state, step: state.step + 1};
    },
    yyxq(state = {}, {payload = {}}) {
      return {...state, yyxq: payload};
    },
    sksj(state = {}, {payload = {}}) {
      return {...state, sksj: payload};
    },
    step(state = {}, {payload = {}}) {
      return {...state, step: payload};
    },
  },
};
